package cs275.ants.graphics;

import java.io.IOException;

import com.jme.math.Vector3f;
import com.jme.scene.TriMesh;
import com.jme.scene.shape.Sphere;
import com.jmex.effects.particles.ParticleMesh;

import cs275.ants.graph.Maze;
import cs275.ants.graph.MazeGenerator;

import junit.framework.TestCase;

public class CharacterTest extends TestCase {

	private Resources resource;

	@Override
	protected void setUp() throws Exception {
		resource = new MockResources();
	}
	
	public void testMoveTo() {
		MazeGenerator mazeGenerator = new MazeGenerator();
		CharacterGenerator charGen = new CharacterGenerator(resource);
		MockGraphics graphics = new MockGraphics(mazeGenerator, charGen,
				new ParticleGenerator(resource));

		Character c = charGen.generate();
		Maze maze = mazeGenerator.generate(3, 3);
		c.setUp(maze, graphics);
		c.getModel().setLocalTranslation(new Vector3f(0,0,0));
		assertFalse(c.isUpdate);
		Vector3f bound = graphics.getCellScreenCoordinate(1, 1);
		Vector3f destination = graphics.getCellScreenCoordinate(0, 1);
		
		c.setDestination(destination);
		assertTrue(c.isUpdate);
		for (int i = 0; i < c.MAXSTEP + 1; i++) {
			c.update();
		}
		assertFalse(c.isUpdate);
		assertTrue(c.getModel().getLocalTranslation().x <= destination.x
				+ bound.x / 2
				&& c.getModel().getLocalTranslation().x >= destination.x
						- bound.x / 2);
		assertTrue(c.getModel().getLocalTranslation().z <= destination.z
				+ bound.z / 2
				&& c.getModel().getLocalTranslation().z >= destination.z
						- bound.z / 2);

	}


	private static class MockResources extends Resources {
		@Override
		public TriMesh antMesh() throws IOException {
			return new TriMesh();
		}
		
		@Override
		public ParticleMesh particleMesh() {
			return new ParticleMesh();
		}
	}

	private static class MockGraphics extends Graphics {

		public MockGraphics(MazeGenerator mazeGenerator,
				CharacterGenerator characterGenerator,
				ParticleGenerator particleGenerator) {
			super(mazeGenerator, characterGenerator, particleGenerator);
			// TODO Auto-generated constructor stub
		}

		public Vector3f getCellScreenCoordinate(int row, int col) {
			return new Vector3f(10 * col, 0, 10 * row);
		}
	}
	
}
